COMMIT := $(shell git describe --dirty --always)
LDFLAGS := "-s -w -X main.GitCommit=$(COMMIT)"
DOCKER_IMAGE ?= darrel999/ipctl
BPF_CFLAGS =-D__KERNEL__ -D__ASM_SYSREG_H \
	-Wunused \
	-Wall \
	-Wno-compare-distinct-pointer-types \
	-fno-stack-protector \
	-Wno-pointer-sign \
	-O2 -S -emit-llvm
generate:
	go generate ./...

build:
	go build -ldflags "-s -w"  -o ipctl cmd/main.go 
	
xdp:
	clang -O2 -target bpf  -I ./headers  -g -o ebpf/xdp.o -c ebpf/xdp.c 
	
lint:
	golangci-lint run

test:
	go test -race ./...  -v

docker: Dockerfile test
	docker buildx build --push \
	--platform linux/amd64 \
	--build-arg LDFLAGS=$(LDFLAGS) \
	-t $(DOCKER_IMAGE):$(COMMIT) \
	-t $(DOCKER_IMAGE):latest .
clean:
	rm -f kprobe/bpf_*
	rm -f pkg/xdp/bpf_*
